import { getOrderStatus, getGoodsStatus, getSupplyReason, getSupplyStatus } from "./global"
import globalData from './global'
export const globalMixin = {
  data() {
    return {
      statusList: [],
      goodsStatus: [],
      reasonList: [],
      supplyStatus: []
    }
  },
  watch: {
    statusList() {
      this.fetchOrderStatus()
    },
    goodsStatus() {
      this.fetchGoodsStatus()
    },
    reasonList() {
      this.fetchSupplyReason()
    },
    supplyStatus() {
      this.fetchSupplyStatus()
    }
  },
  created() {
    this.fetchOrderStatus()
    this.fetchGoodsStatus()
    this.fetchSupplyReason()
    this.fetchSupplyStatus()
  },
  methods: {
    async fetchOrderStatus() {
      if (globalData.orderStatus && globalData.orderStatus.length > 0) {
        this.statusList = globalData.orderStatus
      } else {
        this.statusList = await getOrderStatus()
      }
    },
    async fetchGoodsStatus() {
      if (globalData.goodsStatus && globalData.goodsStatus.length > 0) {
        this.goodsStatus = globalData.goodsStatus
      } else {
        this.goodsStatus = await getGoodsStatus()
      }
    },
    async fetchSupplyReason() {
      if (globalData.boxSupplyReason && globalData.boxSupplyReason.length > 0) {
        this.reasonList = globalData.boxSupplyReason
      } else {
        this.reasonList = await getSupplyReason()
      }
    },
    async fetchSupplyStatus() {
      if (globalData.boxSupplyStatus && globalData.boxSupplyStatus.length > 0) {
        this.supplyStatus = globalData.boxSupplyStatus
      } else {
        this.supplyStatus = await getSupplyStatus()
      }
    }
  },
}